<?php
/*
 +----------------------------------------------------------------------
 + Title        : SmsLogic 控制器
 + Author       : Randy_chen
 + Version      : V1.0.0.1
 + Initial-Time : 2021/3/9 22:10
 + Last-time    : 2021/3/9 22:10+ chen2
 + Desc         : SmsLogic
 +----------------------------------------------------------------------
*/

namespace app\common\service;



use think\facade\Cache;
use utils\Alidayu;

class SmsService {

	//发送验证码
    /**
     * @throws \Exception
     */
    public static function sendCode($mobile, $type) : bool
    {
		$code = rand(1000, 9999);
		$res = Alidayu::sendNotice($mobile, $code);
		if ($res) {
		    $key = sprintf('sms-%s:%s' , $type , $mobile);
			Cache::set($key , $code , 60*3);
			return true;
		}
		return false;
	}
}